/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.website.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nmf.site.common.PageDb;
import org.apache.commons.lang3.StringUtils;

import com.nmf.dao.gen.bean.BizWeb;
import com.nmf.dao.gen.bean.BizWebExample;
import com.nmf.dao.gen.BizWebMapper;
import com.nmf.site.common.enums.DelFlagEnums;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.utils.IdGenerater;

/**
 * 网站信息Service
 * @author bm
 * @version 2019-01-25
 */
@Service
@Transactional(readOnly = true)
public class BizWebService{

	@Autowired
	BizWebMapper bizWebMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizWeb get(String no) {
		return bizWebMapper.selectByPrimaryKey(no);
	}
	
	public List<BizWeb> findList(BizWeb bizWeb) {
		BizWebExample bizWebExample = new BizWebExample();
		BizWebExample.Criteria criteria = bizWebExample.createCriteria();
		
		return bizWebMapper.selectByExample(bizWebExample);
	}
	
	public Page<BizWeb> findPage(Page<BizWeb> page, BizWeb bizWeb) {
		BizWebExample bizWebExample = new BizWebExample();
		BizWebExample.Criteria criteria = bizWebExample.createCriteria();
		
		bizWebExample.setPage(page);
		
		List<BizWeb> dlist = bizWebMapper.selectByExample(bizWebExample);
		page.setList(dlist);
		page.setCount(bizWebMapper.countByExample(bizWebExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BizWeb bizWeb) {
		if(StringUtils.isNotEmpty(bizWeb.getId())&&get(bizWeb.getId())!=null) {
			bizWebMapper.updateByPrimaryKeySelective(bizWeb);
		}else {
			Date date = new Date();
			bizWeb.setCreateDate(date);
			bizWeb.setId(idGenerater.genClsNo("bizWeb"));
			bizWeb.setUpdateDate(date);
			bizWebMapper.insertSelective(bizWeb);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizWeb bizWeb) {
		bizWebMapper.deleteByPrimaryKey(bizWeb.getId());
	}
	
}